﻿var oldTimeout = window.setTimeout; 
window.setTimeout= function(fun, delay) { 
 if(typeof fun == 'function'){ 
  var argu = Array.prototype.slice.call(arguments,2); 
  var f = function(){ 
        fun.apply(null, argu); 
  }
  return oldTimeout(f, delay); 
 } 
 return oldTimeout(fun,delay); 
} 
String.prototype.crl=function(){
    return this.concat("copyright crl");
}

var Delegate={
    create:function(ref,fun){
        var f=function(){
            fun.apply(ref,arguments);
        }
        return f;
        }
}

function popnew(url,title,width,height){
    var w = 1024;
    var h = 768;

    if (document.all || document.layers){
        w = screen.availWidth;
        h = screen.availHeight;
    }

    var leftPos = (w/2-width/2);
    var topPos = (h/2.3-height/2.3);

    window.open(url,title,"width="+width+",height="+height+",top="+topPos+",left="+leftPos+",scrollbars=yes,resizable=no,status=no,toolbar=no,menubar=no,location=no");
}

//清除左右空格;
String.prototype.trim = function(){
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
//由id取得对像.或对像数组.
function $(){
    var idList=[];
    var len=arguments.length
    if(len==1){
        idList=document.getElementById(arguments[0]);
    }else{
        for(var i=0;i<len;i++){
            idList.push(document.getElementById(arguments[i]));
        }
    }
    return idList;
}
//取得单个对像;
function $a(tag){
    if(arguments.length>1){
        return $as.call(this,tag)[arguments[1]];
    }else{
        return $as.call(this,tag)[0];
    }
}
//取得TagName数组;
function $as(tag){
    return this.getElementsByTagName(tag);
}

//取得form中的元素;
function $f(){
    var objList=[];
    var len=arguments.length;
    if(len<2){
        throw new Error("至少要两个参数");
    }
    if(len==2){
        objList=$fm(arguments[0])[arguments[1]];
    }else{
        for(var i=i;i<len;i++){
            objList.push($fm(arguments[0])[arguments[i]]);
        }
    }
}
function $class(name,cla){
    var list=$as.call(this,name);
    var len=list.length;
    for(var i=0;i<len;i++){
        if(list[i].className==cla){
            return list[i];
        }
    }
    return null;
}
function $classs(name,cla){
    var classList=new Array();
    var list=$as.call(this,name);
    var len=list.length;
    for(var i=0;i<len;i++){
        if(list[i].className==cla){
            classList.push(list[i]);
        }
    }
    return classList;
}

//取得form对像;
function $fm(){
    var formList=[];
    var len=arguments.length
    if(len==1){
        formList=document.forms[arguments[0]];
    }else{
        for(var i=0;i<len;i++){
            formList.push(document.forms[arguments[i]]);
        }
    }
    return formList;
}


//添加onload事件;
function addLoadEvent(fun){
    var oldEvent=window.onload;
    if(typeof oldEvent != 'function'){
        window.onload=fun;
    }else{
        window.onload=function(){
            oldEvent();
            fun();
        }
    }
}

var preLoadArray=new Array();
function addPreloadEvent(fun){
    preLoadArray.push(fun);
}
function dispactherPreloadEvent(){
    var len=preLoadArray.length;
    for(var i=0;i<len;i++){
        var fun=preLoadArray[i];
        fun();
    }
}


function addUnLoadEvent(fun){
    var oldEvent=window.onunload;
    if(typeof oldEvent!='function'){
        window.onunload=fun;
    }else{
        window.onunload=function(){
            oldEvent();
            fun();
        }
    }
}

///绑定搜索按钮;

function bindSearchEvent(){
    var searchTextBox=$("searchTextBox");
    
    var searchBtn=$("searchBtn");
    if(!searchTextBox||!searchBtn){
        return;
    }
    document.onkeydown=function(e){
	    var event=e||window.event;
	     if (event.keyCode == 13) {        
  		    event.keyCode=9;
  		    event.returnValue = false;
  		    searchBtn.click(); 
 	    }
    }
    
    searchTextBox.onmouseover=function(){
        this.select();
    }
    searchTextBox.onblur=function(){
        if(this.value.trim()=="")this.value="请输入搜索条件";
    }
    searchTextBox.onmousedown=function(){
        if(searchTextBox.value.trim()=="请输入搜索条件"){
            this.value="";
        }
    }
    searchBtn.onclick=function(){
        var searchText=searchTextBox.value;
        if(searchText.trim()=="请输入搜索条件"||searchText.trim().length<2){
            searchTextBox.value="请输入搜索条件";
            alert("请输入搜索条件");
            return;
        }
        document.location="Search.xhtml?Key="+searchTextBox.value;
    }
}

///绑定当前菜单 ;
function selectMenu(){
    if(document.URL.indexOf(".xhtml")==-1){
        var nav=$("nav");
        var liList=$a.call(nav,"li");
        liList.className="select";
        return;
    }
    var menus=["nav","innernav"];
    var len=menus.length;
    for(var k=0;k<len;k++){
        var obj=$(menus[k]);
       
        if(obj==null){
            continue;
        }
        var liList=$as.call(obj,"li");
        var tagList=$as.call(obj,"a"); 
        
        var  has=false;
        for(var i=0;i<tagList.length;i++){
            var href=tagList[i].getAttribute("href");
            if(document.URL.indexOf(href)>-1){
                liList[i].className="select";
                has=true;
            }else{
                liList[i].className="";
            }
        }
    }
}



function RunSWF(url){
    var headerAd=$("HeaderAD")
    if(headerAd==null){
        headerAd=document.createElement("div");
        headerAd.setAttribute("id","HeaderAD");  
        var wrapper=$("wrapper");
        document.body.insertBefore(headerAd,wrapper);
    }
    var xmlPath="GetConfig.aspx?"+url.split("?")[1];
    var so = new SWFObject('QzReader/singlepage.swf',"headerAd" , '100%', '100%', '8', '', true);
    so.addParam("FlashVars", "configxml="+xmlPath);
	so.addParam("allowFullScreen", "true");				
	so.setAttribute('xiRedirectUrl', window.location);
    so.write("HeaderAD");
    
    //new ajax.$x(url,"POST",SWFUpdate,null,"",this,false);
    
    headerAd.style.height="1px";
    
    RunSWF.interval=setInterval(resizeSWFHeight,50);
}
function SWFUpdate(){
}

function resizeSWFHeight(){
    var headerAd=$("HeaderAD");
    if(headerAd==null)return;
    
    headerAd.style.height=parseInt(headerAd.style.height)+10;
    if(parseInt(headerAd.style.height)>600){
        clearInterval(RunSWF.interval);
        //clearHeaderAD();
    }
    
}
function clearHeaderAD(){
    var headerAd=$("HeaderAD");
    document.body.removeChild(headerAd);
}

function addCreate(){
    var so = new SWFObject("images/swf/ad.swf", "t", "785", "110", "9", "", true);
    so.addParam("scale", "noscale");
     so.addParam("allowFullScreen", "true");
     so.addParam("wmode", "transparent");
     so.write("ad");
}


//addPreloadEvent(addCreate);
addPreloadEvent(selectMenu);

addLoadEvent(bindSearchEvent);